package cn.hl.sfzy.service.impl;

import cn.hl.sfzy.entity.Article;
import cn.hl.sfzy.entity.Systemuser;
import cn.hl.sfzy.mapper.SystemuserMapper;
import cn.hl.sfzy.service.SystemuserService;
import cn.hl.sfzy.util.MD5Util;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName SystemuserServiceImpl
 * @Description TOOO
 * @Author Lilysi
 * @Date 2024//10//22//16:36
 * @Version 1.0
 */
@Service
public class SystemuserServiceImpl implements SystemuserService {
    @Autowired
    private SystemuserMapper systemuserMapper;
    @Override
    public Systemuser getSystemuser(Systemuser systemuser) {

        String username=systemuser.getUsername();
        String password=systemuser.getPassword();
        String encode = MD5Util.encode(username + password);
        password=encode;
        System.out.println(encode);
        Systemuser user = systemuserMapper.selectByUsernameAndPassword(username, password);
        return user;
    }



    @Override
    public int delete(Long id) {
        int delete = systemuserMapper.delete(id);
        return delete;
    }

    @Override
    public int update(Systemuser systemuser) {
        int update = systemuserMapper.update(systemuser);
        return update;
    }

    @Override
    public int insert(Systemuser systemuser) {
        String username=systemuser.getUsername();
        String password=systemuser.getPassword();
        String encode = MD5Util.encode(username + password);
        systemuser.setPassword(encode);
        int insert = systemuserMapper.insert(systemuser);
        return insert;
    }

    @Override
    public PageInfo<Systemuser> findByPage(int pageNum, int pageSize, Systemuser systemuser) {
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<Systemuser> articlePageInfo = new PageInfo<>(systemuserMapper.select(systemuser));
        return articlePageInfo;
    }
}
